package com.globallogic.training.javase.university.curriculum;

import java.util.Set;
import java.util.TreeSet;

import com.globallogic.training.javase.university.member.Group;

/**
 * Curriculum is the set of subjects, and their content for university group.
 * 
 * @author Artem.Zeltinsh
 */
public class Curriculum {

	private Group group;

	private Set<Subject> subjects;

	public Curriculum(Group group) {
		this.group = group;
		this.subjects = new TreeSet<Subject>();
	}

	public boolean add(Subject subject) {
		return subjects.add(subject);
	}

	public boolean remove(Subject subject) {
		return subjects.remove(subject);
	}

	public Subject getSubject(String id) {
		
		for (Subject subject : subjects) {
			if (subject != null && subject.getId().equals(id)) {
				return subject;
			}
		}

		return null;
	}

	public Subject[] getSubjects() {
		return subjects.toArray(new Subject[subjects.size()]);
	}

	public Group getGroup() {
		return group;
	}

	@Override
	public String toString() {
		return "curriculum for " + group + " " + subjects;
	}
}
